<template>
   <div class="recycle-merchandise  views-container">
    <div class="wlm-table">
        <div class="wlm-table-header">
               <el-form size="small" class="retail-form" label-position="right" :model="tableFormatData.commodityaudit.files">
                            <el-form-item label="商品名称：" class="search">
                                <!--  -->
                                <el-input v-model="tableFormatData.commodityaudit.files.goods_name" placeholder="请输入商品名称" style="width:160px;"></el-input>
                            </el-form-item>
                            <!-- <el-form-item label="商品分类：">
                                <el-cascader :props="myProps" :options="categoryData" :show-all-levels="false" v-model="category_array" @change="categoryChange">
                                </el-cascader>
                            </el-form-item> -->
                            <el-form-item label="" class="filter-btns">
                              <el-button  type="primary" @click="filesSerch">筛选</el-button>
                              <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                            </el-form-item>
               </el-form>
         </div>
        <div class="wlm-table-content">
            <!-- <el-tabs v-model="tableFormatData.announcement.files.goodsType" type="card" @tab-click="filesSerch">
              <el-tab-pane :label="`已通过(${goodsType.sale})`" name="sale"></el-tab-pane>
              <el-tab-pane :label="`未通过(${goodsType.hasSale})`" name="hasSale"></el-tab-pane>
              <el-tab-pane :label="`已拒绝(${goodsType.depot})`" name="depot"></el-tab-pane>
            </el-tabs> -->
             <el-table :ref="tableFormatData.commodityaudit.key" :data="tableFormatData.commodityaudit.tableData" @selection-change="handleSelectionChange"  style="width: 100%">
                <el-table-column type="selection" width="55" :selectable='selectInit'>
                </el-table-column>
                <el-table-column prop="date" label="商品图片">
                    <template slot-scope="scope" v-if="scope.row.goods.image">
                        <img style="width:50px;height:50px;" :src="scope.row.goods.image[0]['file_path']">
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="商品信息">
                     <template slot-scope="scope">
                         <el-tag size="mini" v-if="scope.row.goods.transport_type==10">{{'核销商品'}}</el-tag>
                         <el-tag size="mini" type="success" v-if="scope.row.goods.transport_type==20">{{'实物商品'}}</el-tag>
                         <el-tag size="mini"  type="info" v-if="scope.row.goods.transport_type==30">{{'卡密商品'}}</el-tag>
                         <el-tag size="mini" type="warning" v-if="scope.row.goods.transport_type==40">{{'团购商品'}}</el-tag>
                         <el-tag size="mini"  type="danger" v-if="scope.row.goods.transport_type==50">{{'礼包商品'}}</el-tag>
                        <span>{{scope.row.goods.goods_name}}</span>
                     </template>
                </el-table-column>
                <!-- <el-table-column prop="date" label="商品分类" >
                  <template slot-scope="scope" v-if="scope.row.goods.category_data">
                    <p v-for="(item, index) in scope.row.goods.category_data" :key="index" >{{`${item.child?item.child.length>1?item.child.join('/'):item.child[0]:''}`}}</p>
                    <p v-if="scope.row.goods.category_data.length==0">-</p>
                  </template>
                </el-table-column> -->
                <el-table-column prop="date" label="价格">
                     <template slot-scope="scope">
                         <span>{{scope.row.goods.sku[0].goods_price}}</span>
                     </template>
                </el-table-column>
                <el-table-column prop="date" label="库存">
                  <template slot-scope="scope">
                    <span>{{scope.row.goods.sku[0].stock_num}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="date" label="商家信息" >
                   <template slot-scope="scope">
                     <span>{{scope.row.business? scope.row.business.name :''}}</span>
                       <!-- <template slot-scope="scope">
                        <router-link tag="span" :to="{path:'/merchant/storeListMerchant', query :{ bus_id:scope.row.id}}">
                            <span class="pointer">{{scope.row.storenum}}</span>
                        </router-link>
                    </template> -->
                      <!-- <span  @click="$router.push({path:'/merchant/businessAdd',query:{id:scope.row.bus_id}})">{{scope.row.bus_name}}</span> -->
                     <div class="pointer"  @click="$router.push({path:'/merchant/storeListMerchant',query:{bus_id:scope.row.bus_id}})">{{scope.row.goods.store_id==0?scope.row.storeall.length:scope.row.goods.store_id.length}}家门店</div>
                   </template>
                </el-table-column>
                <el-table-column prop="date" label="状态">
                   <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.goods.goods_status==10">{{'已上架'}}</el-tag>
                    <el-tag type="danger" v-if="scope.row.goods.goods_status!=10">{{'未上架'}}</el-tag>
                    <el-tag type="success" v-if="scope.row.status==1">{{'已通过'}}</el-tag>
                    <el-tag type="warning" v-if="scope.row.status==2">{{'未通过'}}</el-tag>
                    <el-tag type="info" v-if="scope.row.status==3">{{'待审核'}}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="date" label="操作" >
                   <template slot-scope="scope">
                     <div class="operation-group" v-if="scope.row.status!=1">
                            <el-button class="wlm-text" type="text" @click="entering(scope.row.audit_id)">通过</el-button>
                            <div class="btn-line"></div>
                            <!-- @click="delTableItem(scope.row.id)" -->
                            <el-button class="wlm-text" type="text" @click="enteringbtn(scope.row.audit_id)">拒绝</el-button>
                        </div>
                        <div v-if="scope.row.status==1">-</div>
                   </template>
                </el-table-column>
             </el-table>
        </div>
        <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.commodityaudit.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" type="primary"  :disabled="isGroup" size="mini"  @click="auditBatch({redirect:'ids',id:'all',toggle:'dialogTableVisible',noEdit:true})">批量审核</el-button>
                </el-row>
                <el-pagination
                    :disabled="!hasTableData"
                    @size-change="listPageChange"
                    @current-change="listPageChange"
                                    :current-page.sync="tableFormatData.commodityaudit.pagination.page"
                    :page-sizes="tableFormatData.commodityaudit.pagination.pagesizes"
                                    :page-size.sync="tableFormatData.commodityaudit.pagination.list_rows"
                    layout="total, sizes, prev, pager, next, jumper"
                 :total="hasTableData?tableFormatData.commodityaudit.pagination.total : 0">
                </el-pagination>
            </div>
    </div>
   </div>
</template>
<script>
import {
  getAuditList,
  setAudit
} from '@/api/merchandise'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'Commodityaudit',
  data() {
    return {
      dialogTableVisible: false,
      popvisible: false,
      tableFormatData: {
        current: 'commodityaudit',
        commodityaudit: {
          key: 'commodityaudit',
          api: {
            getList: getAuditList
            // delList: goodsDelete
          },
          tableData: [],
          files: {
            ids: [],
            checkall: '0',
            goods_name: ''
            // status:1,
          },
          otherData: {},
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      },
      formFormatData: {
        key: 'commodityaudit',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
            // api: applyCheck,
            params: {
              id: ''
            }
          }
        //   submitForm: applyCheck
        },
        formData: {
          ids: []
        //   content: '',
        //   status: '20'
        },
        rules: {

        }
      }
    }
  },
  methods: {
    selectInit(row, index) {
      if (row.status == 1) {
        return false // 不可勾选
      } else {
        return true // 可勾选
      }
      // console.log('resssssssssssssssssssssss', row, index)
    },
    auditBatch(params) {
      this.formFormatDialogEditEvt(params)
      var array = []
      this.tableFormatData.commodityaudit.files.ids.map((item) => {
        console.log('itemssssssssssss', item)
        if (item.status != 1) {
          array.push(item.audit_id)
        }
      })
      this.formFormatData.formData.ids = array
      // this.formFormatData.formData.ids = [audit_id]
      console.log('this.formFormatData.formData.ids', this.formFormatData.formData.ids)
      this.$confirm('确定批量审核通过吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        setAudit({ audit_id: array, status: 1 }).then(res => {
          const { data: { code, msg } } = res
          if (code == 1) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.filesEmpty()
          } else {
            this.$message.error(msg)
          }
        })
      }).catch(res => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    entering(audit_id) {
      this.$confirm('确定通过该商品审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        setAudit({ audit_id: audit_id, status: 1 }).then(res => {
          const { data: { code, msg } } = res
          if (code == 1) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.filesEmpty()
          } else {
            this.$message.error(msg)
          }
        })
      }).catch(res => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    enteringbtn(audit_id) {
      this.$confirm('确定拒绝该商品审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        setAudit({ audit_id: audit_id, status: 2 }).then(res => {
          const { data: { code, msg } } = res
          if (code == 1) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.filesEmpty()
          } else {
            this.$message.error(msg)
          }
        })
      }).catch(res => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
